// Copyright 2017 guangbo. All rights reserved.

// 节点1，负责运行网关
// ./game1 -h 127.0.0.1:19876 -n game1
package main

import (
	"flag"
	"gitee.com/goxiang2/server/lib/lib_config"
	"gitee.com/goxiang2/server/lib/lib_rpc"
	"gitee.com/goxiang2/server/lib/lib_watch"
	_ "gitee.com/goxiang2/server/service/gate"
	"log"
	"net/http"
	_ "net/http/pprof"
)

var name = flag.String("n", "", "server port name")
var host = flag.String("h", "", "watch address")

func main() {
	flag.Parse()

	if *name == "" || *host == "" {
		flag.Usage()
		return
	}

	go http.ListenAndServe("0.0.0.0:7070", nil)

	// 初始化center客户端
	client, err := lib_watch.NewWatchClient(*host)
	if err != nil {
		log.Println(err)
		return
	}
	client.RegisterCallback(lib_config.CmdKey, lib_rpc.WatchCmd)
	client.RegisterCallback(lib_config.NodeRegisterKey, lib_rpc.WatchNodeRegister)
	client.Start()

	//rpc节点服务
	lib_rpc.InitNode(client, *name)
}
